package concrete;

import java.util.Random;

/*  The Dice class will generate the random numbers needed for the game just like 
    conventional dice  */

public class Dice {


	//VARIABLES
	private int[] numbers = new int[2];
	private boolean doublesMode;
	private boolean neverDoubles;
	Random random = new Random(); //this object is used for getting random integers for the dice


	public Dice() {
		this.numbers[0] = 0;
		this.numbers[1] = 0;
		this.doublesMode = false;
		this.neverDoubles = false;
	}
	
	//GETTERS
	public int getNumber(int i)
	{
		//int diceValue;
		
		//if(this.doublesMode)
		//	diceValue = this.numbers[0];
		//else
		//	diceValue = this.numbers[i-1];
		
		//return diceValue;
		return this.numbers[i-1];
	}
	public int[] getNumbers()
	{
		return this.numbers;
	}
	public boolean getDoublesMode() {
		return this.doublesMode;
	}
	public boolean getNeverDoubles() {
		return this.neverDoubles;
	}


	//SETTERS
	public void setFirstNumber(int number) {
		this.numbers[1] = number;
	}
	public void setSecondNumber(int number)	{
		this.numbers[2] = number;
	}
	public void setNumbers(int[] numbers) {
		this.numbers = numbers;
	}
	public void setDoublesMode(boolean doublesMode) {
		this.doublesMode = doublesMode;
	}
	public void setNeverDoubles(boolean neverDoubles) {
		this.neverDoubles = neverDoubles;
	}


	//OTHER METHODS
	//Method that randomly generates 2 integer values to be stored in the array
	public void rollDice() {
		for(int i=0; i<2; i++) {
			long range=(long)6 - (long)1 + 1;
			long fraction=(long)(range * random.nextDouble());
			this.numbers[i]=(int)(fraction + 1);
		}
		
		if(this.neverDoubles && this.numbers[0]==this.numbers[1]) {
			if(6>numbers[1]) {
				this.numbers[1] = this.numbers[1] + 1;
			}
			else {
				this.numbers[1] = 1;
			}
		}
		else {
			if(this.doublesMode) {
				this.numbers[1] = this.numbers[0];
			}
		}
	}

}